﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Media.Imaging;
using System.Xml;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;

namespace YArchitech.Public
{
	internal static class CmdTools
	{
		public static bool RibbonEnabled { get; set; }

		public static void Idling(object sender, IdlingEventArgs e)
		{
		}

		public static void DisableRibbon()
		{
			foreach (string text in CmdTools.listTabName)
			{
				foreach (RibbonPanel ribbonPanel in CmdTools.uiApp.GetRibbonPanels(text))
				{
					foreach (RibbonItem ribbonItem in ribbonPanel.GetItems())
					{
						ribbonItem.Enabled = false;
					}
				}
			}
		}

		public static string hyGetPath()
		{
			return Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) + "\\Data\\SelSets.xml";
		}

		public static XmlNodeList hyGetSelList()
		{
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(CmdTools.hyGetPath());
			return xmlDocument.SelectNodes("SelSets/SelSet");
		}

		public static void cdLoadSet(ExternalCommandData revit)
		{
			RibbonPanel ribbonPanel = null;
			foreach (RibbonPanel ribbonPanel2 in revit.Application.GetRibbonPanels("工具"))
			{
				if (ribbonPanel2.Name == "选择集")
				{
					ribbonPanel = ribbonPanel2;
					break;
				}
			}
			ComboBox comboBox = null;
			foreach (RibbonItem ribbonItem in ribbonPanel.GetItems())
			{
				if (ribbonItem.Name == "selList")
				{
					comboBox = (ribbonItem as ComboBox);
				}
			}
			if (comboBox != null)
			{
				foreach (ComboBoxMember comboBoxMember in comboBox.GetItems())
				{
					comboBoxMember.Visible = false;
				}
				XmlDocument xmlDocument = new XmlDocument();
				string text = Assembly.GetExecutingAssembly().Location;
				text = Path.GetDirectoryName(text);
				text = Path.GetDirectoryName(text);
				string filename = text + "\\Data\\SelSets.xml";
				xmlDocument.Load(filename);
				XmlNodeList xmlNodeList = xmlDocument.SelectNodes("SelSets/SelSet");
				string uriString = text + "\\Res\\CreateWall-S.png";
				foreach (object obj in xmlNodeList)
				{
					XmlNode xmlNode = (XmlNode)obj;
					ComboBoxMember comboBoxMember2 = comboBox.AddItem(new ComboBoxMemberData(Guid.NewGuid().ToString(), xmlNode.Attributes["Text"].Value));
					comboBoxMember2.Image = new BitmapImage(new Uri(uriString, UriKind.Absolute));
					comboBox.Current = comboBoxMember2;
				}
			}
		}

		public static UIControlledApplication uiApp = null;

		public static List<string> listTabName = new List<string>();

		public static Dictionary<string, HYRibbonItemToolTipData> HYRibbonItems = new Dictionary<string, HYRibbonItemToolTipData>();
	}
}
